<?php
//require_once "lib/nusoap.php";

$my_url = 'http://localhost/fashion_services/';
$hostname="1.234.91.160";
$username="cam";
$password="5678";
$databasename="fashion";
//echo date("Y-m-d");
function LogInMember($user, $pass) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT * FROM member m WHERE (m.mem_id='$user' AND m.mem_pswd='$pass' AND m.status='1')");


	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return json_encode($r);
	}else{
		mysql_close($conn);
		return '{}';
	}
}

function GetInfoMember($user) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT * FROM member m WHERE (m.mem_id='$user' AND m.status='1')");



	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return  json_encode($r);
	}else{
		mysql_close($conn);
		return  '{}';
	}
}

function ChangePasswordMember($user, $passOld, $passNew) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("UPDATE member SET mem_pswd='$passNew' WHERE (mem_id='$user' AND mem_pswd='$passOld' AND status='1')");

	$rs=mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function CreateNewMember($user, $pass, $alias,$pic, $profile) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$check=mysql_query("SELECT * FROM member m WHERE m.mem_id='$user'");
	if(mysql_num_rows($check)>0){
		mysql_close($conn);
		return  '-1';
	}else{
		$result=mysql_query("INSERT INTO `member` (`mem_id`, `mem_pswd`, `mem_name`, `mem_pic`, `mem_profile`, `mem_joinday`, `status`) VALUES ('$user', '$pass', '$alias', '$pic', '$profile', NOW(), '1')");
		$rs=mysql_affected_rows();
		mysql_close($conn);
		return $rs;
	}
}

function GetFashionDay($day, $country) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");
	//include '../connect/common_start.php';
	$curDay= date("Y-m-d");
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));
	$sql="SELECT p.* FROM post p, store s WHERE  p.date='$NewDate' AND p.type='1' AND p.id_store=s.id AND s.`status`=1 AND s.store_area='$country'";
	//$result=mysql_query("SELECT * FROM post m WHERE (m.date='$NewDate' AND m.status='1')");
	$result=mysql_query($sql);
	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	//include '../connect/common_end.php';
	mysql_close($conn);
	$rs=json_encode($rows);
	return $rs;
}

function GetListProduct($idPost) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT * FROM product p WHERE (p.id_post='$idPost' AND p.status='1')");

	$row=array();
	while ($r=mysql_fetch_assoc($result)) {
		$row[] = $r;
	}
	mysql_close($conn);
	return  json_encode($row);
}

function GetLikeMember($mem_id,$idPost) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post='$idPost'");
	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return  json_encode($r);
	}else{
		mysql_close($conn);
		return  '{}';
	}
}

function SetLikePost($mem_id, $post_id, $type) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `post` SET `likes`=`likes`+'$type' WHERE (`id`='$post_id')";

	$result1=mysql_query($sql);

	$result=mysql_query("INSERT INTO `like` (`id_mem`, `id_post`, `like`, `datetime`) VALUES ('$mem_id', '$post_id', '$type', NOW())");
	$rs=mysql_affected_rows();
	mysql_close($conn);
	return $rs;
}

function GetListCommentPost($post_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT c.id,c.id_mem,c.id_post,c.cm_id,c.cm_content,c.date,m.mem_id as'mem_id',m.mem_name,m.mem_pic FROM `comment` c JOIN member m ON c.id_mem=m.id WHERE (c.id_post='$post_id' AND c.status='1') ORDER BY c.date");

	$row=array();
	while ($r=mysql_fetch_assoc($result)) {
		$row[]=$r;
	}
	mysql_close($conn);
	return json_encode($row);
}

function AddCommentPost($mem, $idPost, $cmid, $cmcontent) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `post` SET `comments`=`comments`+'1' WHERE (`id`='$idPost')";
	$result1=mysql_query($sql);

	$result=mysql_query("INSERT INTO `comment` (`id_mem`, `id_post`, `cm_id`, `cm_content`, `date`, `status`) VALUES ('$mem', '$idPost', '$cmid', '$cmcontent',NOW(),'1')");
	$rs= mysql_affected_rows();
	mysql_close($conn);
	return $rs;
}

function CreateNewPost($mem_id, $year, $month, $day, $title, $price, $link, $image, $content) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	//$date = date_create($year.'-'.$month.'-'.$day);
	//$date= date_format($date, 'Y-m-d');
	$date = $year.'-'.$month.'-'.$day;
	//echo $date;
	$title=urldecode($title);
	$price=urldecode($price);
	$link=urldecode($link);
	$content=urldecode($content);
	$sql="INSERT INTO `post` (`id_store`, `date`, `title`, `price`, `link`, `image`, `content`, `create_day`, `status`, `likes`, `comments`, `type`) VALUES ('$mem_id', '$date', '$title', '$price', '$link', '$image', '$content', NOW(), '0','0','0' ,'2')";
	//echo $sql;
	$result=mysql_query($sql);

	$rs= mysql_affected_rows();
	mysql_close($conn);
	return $rs;
}

function GetInfoStore($store_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT * FROM store s WHERE (s.id='$store_id' AND s.status!='0')");
	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return  json_encode($r);
	}else{
		mysql_close($conn);
		return  '{}';
	}
}

function GetInfoFriend($mem_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="SELECT f.id, f.create_date,m.id as friendid, m.mem_id, m.mem_name, m.mem_pic FROM friend f INNER JOIN member m ON f.mem_friend=m.id WHERE f.mem_id='$mem_id' AND f.`status`='1';";
	$result=mysql_query($sql);
	$row=array();
	while ($r=mysql_fetch_assoc($result))
	{
		$row[]=$r;
	}
	mysql_close($conn);
	return  json_encode($row);

}

function AddFriend($mem_id, $mem_id_friend) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="INSERT INTO `friend` (`mem_id`, `mem_friend`, `status`, `create_date`) VALUES ('$mem_id', '$mem_id_friend', '1', NOW()), ('$mem_id_friend', '$mem_id', '1', NOW())";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function DeleteFriend($mem_id, $mem_id_friend) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="DELETE FROM friend WHERE (friend.mem_id='$mem_id' AND friend.mem_friend='$mem_id_friend') OR (friend.mem_id='$mem_id_friend' AND friend.mem_friend='$mem_id')";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function GetFashionMember($mem_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$result=mysql_query("SELECT * FROM post m WHERE (m.id_store='$mem_id')");

	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	mysql_close($conn);
	return json_encode($rows);
}

function GetFashionDayAllMember($day) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	//$day=$_REQUEST['day'];
	//echo '1111'.$day;
	$curDay= date("Y-m-d");
	//echo '2222'.$curDay;
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));



	//echo '3333'.$NewDate;
	$sql="SELECT * FROM post m WHERE (m.type='2' AND m.date='$NewDate' AND m.status='1')";
	//echo $sql;
	$result=mysql_query($sql);

	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	//echo $rows;
	mysql_close($conn);
	return json_encode($rows);
}

function GetLikePost($idPost) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_post='$idPost'";
	$result=mysql_query($sql);
	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return  json_encode($r);
	}else{
		mysql_close($conn);
		return  '{}';
	}

}

function UpdateProfileMember($mem_id,$mem_pass, $profile) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `member` SET `mem_profile`='$profile' WHERE (`mem_id`='$mem_id' AND mem_pswd='$mem_pass' AND status='1' )";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function UpdateImageMember($mem_id,$mem_pass, $mem_pic) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `member` SET `mem_pic`='$mem_pic' WHERE (`mem_id`='$mem_id' AND mem_pswd='$mem_pass' AND status='1' )";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function GetInfoMemberById($id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="SELECT * FROM member m WHERE (m.id='$id' AND m.status='1')";
	$result=mysql_query($sql);
	if(mysql_num_rows($result)>0){
		$r = mysql_fetch_assoc($result);
		mysql_close($conn);
		return json_encode($r);
	}else{
		mysql_close($conn);
		return '{}';
	}
}

function AddNotification($id, $mem_id, $notification, $id_post) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");
	$notification=urldecode($notification);
	$sql="INSERT INTO `notification` (`id`, `mem_id`, `notification`, `id_post`) VALUES ('$id', '$mem_id', '$notification','$id_post')";
	$result=mysql_query($sql);
	$rs=mysql_affected_rows();
	mysql_close($conn);
	return  $rs;
}


function DeleteNotification($id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="DELETE FROM `notification` WHERE (`id`='$id')";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return  $rs;
}

function GetFashionDayFriend($mem_id,$day) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$curDay= date("Y-m-d");
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));
	$sql="SELECT * FROM post p INNER JOIN
							(SELECT f.mem_friend FROM  friend f 
							WHERE f.mem_id='$mem_id' AND f.`status`='1') as f 
							ON p.id_store=f.mem_friend
			WHERE p.date='$NewDate'";
	$result=mysql_query($sql);
	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}

	mysql_close($conn);
	return  json_encode($rows);
}

function GetNotification($id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="SELECT * FROM `notification` WHERE (`mem_id`='$id')";
	$result=mysql_query($sql);

	$sql2="DELETE FROM `notification` WHERE (`mem_id`='$id')";
	$result2=mysql_query($sql2);

	$row=array();
	while ($r=mysql_fetch_assoc($result))
	{
		$row[]=$r;
	}

	mysql_close($conn);
	return  json_encode($row);
}

function GetCountry($ip) {

	$x = gethostbyname($ip);
	//echo $x."<br>";
	$ip_long=sprintf('%u',ip2long($x));
	//echo $ip_long."<br>";
	$row = 1;
	//include 'getCountry/getCountry.php';
	if (($handle = fopen("getCountry/GeoIPCountryWhois.csv", "r")) !== FALSE) {
		while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
			$num = count($data);
			// echo "<p> $num fields in line $row: <br /></p>\n";
			$row++;
			// for ($c=0; $c < $num; $c++) {

			//     echo $data[$c] . "<br />\n";

			// }
			if($data[2]<= $ip_long && $ip_long <= $data[3]){
				$rs= $data[4];
				break;
			}
		}
		fclose($handle);
	}
	return $rs;
}

function UpdateNameMember($mem_id,$mem_pass, $mem_name) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `member` SET `mem_name`='$mem_name' WHERE (`mem_id`='$mem_id' AND mem_pswd='$mem_pass' AND status='1' )";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}

function UpdateMember($mem_id,$mem_pass, $mem_name, $mem_pic) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `member` SET `mem_name`='$mem_name',`mem_pic`='$mem_pic' WHERE (`mem_id`='$mem_id' AND mem_pswd='$mem_pass' AND status='1' )";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return $rs;
}


function GetFashionDayLike($day, $country, $member) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");
	//include '../connect/common_start.php';
	$curDay= date("Y-m-d");
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));
	$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$member' AND l.id_post=p.id)) as islike FROM post p, store s WHERE  p.date='$NewDate' AND p.type='1' AND p.`status`=1 AND p.id_store=s.id AND s.`status`=1 AND s.store_area='$country'";
	//$result=mysql_query("SELECT * FROM post m WHERE (m.date='$NewDate' AND m.status='1')");
	$result=mysql_query($sql);
	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	//include '../connect/common_end.php';
	mysql_close($conn);
	$rs=json_encode($rows);
	return $rs;
}

function GetFashionMemberLike($mem_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	//$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike
	//	FROM post p WHERE (p.id_store='$mem_id' AND p.`status`=1)";
	$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike
		FROM post p WHERE (p.id_store='$mem_id' AND p.`status`=1) ORDER BY p.create_day";
	$result=mysql_query($sql);

	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	mysql_close($conn);
	return json_encode($rows);
}

function GetFashionDayAllMemberLike($day,$mem_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	//$day=$_REQUEST['day'];
	//echo '1111'.$day;
	$curDay= date("Y-m-d");
	//echo '2222'.$curDay;
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));



	//echo '3333'.$NewDate;
	//$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike
	//	FROM post p WHERE (p.type='2' AND p.date='$NewDate' AND p.status='1')";
	
	$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike
		FROM post p WHERE (p.type='2' AND p.status='1') ORDER BY p.create_day";
	
	//echo $sql;
	$result=mysql_query($sql);

	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	//echo $rows;
	mysql_close($conn);
	return json_encode($rows);
}


function GetFashionDayFriendLike($mem_id,$day) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$curDay= date("Y-m-d");
	$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));
	/*$sql="SELECT *,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike FROM post p INNER JOIN
							(SELECT f.mem_friend FROM  friend f 
							WHERE f.mem_id='$mem_id' AND f.`status`='1') as f 
							ON p.id_store=f.mem_friend
			WHERE p.date='$NewDate' AND p.`status`=1" ;*/
	$sql="SELECT *,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike FROM post p INNER JOIN
							(SELECT f.mem_friend FROM  friend f 
							WHERE f.mem_id='$mem_id' AND f.`status`='1') as f 
							ON p.id_store=f.mem_friend
			WHERE (p.`status`=1) ORDER BY p.create_day" ;
	$result=mysql_query($sql);
	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}

	mysql_close($conn);
	return  json_encode($rows);
}

function DeleteFashionMember($mem_id,$id_post) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	$sql="UPDATE `post` SET `status`='2' WHERE (`id`='$id_post' AND `id_store`='$mem_id' AND `type`='2')";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return  $rs;
}

function UpdateFashionMember($mem_id,$id_post,$image,$content) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");	
	$curDay= date("Y-m-d");
	//$NewDate = date('Y-m-d', strtotime($curDay . "$day days"));
	$content=urldecode($content);	
	$sql="UPDATE `post` SET `date`='$curDay', `image`='$image', `content`='$content' WHERE (`id`='$id_post' AND `id_store`='$mem_id' AND `type`='2')";
	$result=mysql_query($sql);
	$rs= mysql_affected_rows();

	mysql_close($conn);
	return  $rs;
}

function GetFashionMemberAndMyLike($mem_id,$my_mem_id) {
	global $hostname;
	global $username;
	global $password;
	global $databasename;
	$conn = mysql_connect($hostname, $username, $password) or
	die("Khong ket noi dc Database !");
	mysql_select_db($databasename);
	mysql_query("SET NAMES 'utf8'");

	//$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$mem_id' AND l.id_post=p.id)) as islike
	//	FROM post p WHERE (p.id_store='$mem_id' AND p.`status`=1)";
	$sql="SELECT p.*,((SELECT SUM(l.`like`) as total FROM `like` l WHERE l.id_mem='$my_mem_id' AND l.id_post=p.id)) as islike
		FROM post p WHERE (p.id_store='$mem_id' AND p.`status`=1) ORDER BY p.create_day DESC";
	$result=mysql_query($sql);

	$rows = array();
	while($r = mysql_fetch_assoc($result)) {
		$rows[] = $r;
	}
	mysql_close($conn);
	return json_encode($rows);
}

//function microtime_float()
//{
//    list($usec, $sec) = explode(" ", microtime());
//    return ((float)$usec + (float)$sec);
//}

//$time_start = microtime_float();

// Sleep for a while
//usleep(100);




//echo LogInMember('aaa','47bce5c74f589f4867dbd57e9ca9f808');
//echo ChangePasswordMember('hung','hung222','hung111');
//echo CreateNewMember('2222222','222222222222','22222222','333333333333','333333');
//echo GetFashionDay('0','VN');
//echo GetListProduct('14');
//echo GetLikeMember('3','2');
//echo SetLikePost('3','2','-1');
//echo GetListCommentPost('3');
//echo AddCommentPost('3','2','321313213','31313123');
//echo CreateNewPost('6', '2013', '11', '15', 'Siu nhung gao do', '1000', '', '', 'hhhhhhhhhhh');
//CreateNewPost{mem_id=6; year=2013; month=11; day=15; title=Siu nhung gao do; price=1000; link=; image=; content=Noi dung cha co gi de ban;
//echo GetInfoStore('10');
//echo GetInfoFriend('1');
//echo AddFriend('1','6');
//echo DeleteFriend('1','6');
//echo GetFashionMember('3');
//echo GetFashionDayAllMember('0');
//echo GetLikePost('2');
//echo UpdateProfileMember('hung','hung','화면 비율 맞추기');
//echo UpdateImageMember('hung','hung','화면 비율 맞추기');
//echo GetInfoMemberById('3');
//echo AddNotification('fsfsf', '1111', 'fsdfsdafsd');
//echo DeleteNotification('fsfsf');
//echo GetFashionDayFriend('3','0');
//echo GetNotification('1');
//echo GetCountry('14.161.37.71');
//echo UpdateNameMember('abc','900150983cd24fb0d6963f7d28e17f72','1111111111111');
//echo UpdateMember('abc','900150983cd24fb0d6963f7d28e17f72','222222222222222','333333333333');
//echo GetFashionDayLike('5','VN','abc');
//echo GetFashionMemberLike('3');
//echo GetFashionDayAllMemberLike('0','3');
//echo GetFashionDayFriendLike('3','0');
//echo GetFashionAllMemberLike('3');
//echo DeleteFashionMember('31','292');
//echo UpdateFashionMember('31','130','jjgjhjg','member_image/abc_1385546629476.jpg');
if(isset($_REQUEST['action']) && $_REQUEST['action']="GetFashionMemberAndMyLike" ){
	//$i1=$_REQUEST['i1'];
	//$i2=$_REQUEST['i2'];
	//
	echo GetFashionMemberAndMyLike('64','31');
}
//$time_end = microtime_float();
//$time = $time_end - $time_start;

//echo "$time seconds\n";